package com.mall.b2c.domain.member;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mall.b2c.enums.SiteNoticeType;
import com.mall.common.domain.BaseEntity;
/**
 * 站内通知--消息
 * @author lzx
 * 若站内通知
 * 	消息类型为系统公告（GLOBLE），
 * 			则新增一条站内信消息同时新增一条StockNoticeDomain（接收者）记录，member字段设为null，表示接收者是所有人。
 *  消息类型为私信（PRIVATE）
 *  		则新增一条站内消息同时新增一条或者多条StockNoticeDomain（接收者）记录，member为接收者id,表示接收者为部分指定的人
 */
@Entity
@Table(name="b2c_site_notice_text")
public class SiteNoticeTextDomain extends BaseEntity {

	private static final long serialVersionUID = 1985508890836125491L;
	
	private String title; // 标题
	private String content; // 内容
	private SiteNoticeType type; //类型
	private String operator; //操作人
	private String outerUrl; // 外部链接
	private Boolean enabledOuterUrl; //启用外部链接
	
	@JsonIgnore 
	private Set<SiteNoticeDomain> siteNotices; //接收者
	
	@PrePersist
	public void prePersist(){
		if(enabledOuterUrl == null){
			enabledOuterUrl = false;
		}
		
		if(outerUrl == null){
			enabledOuterUrl = false;
		}
	}
	
	@Column(nullable=false)
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(length=10000)
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
	
	@Column(nullable=false)
	public SiteNoticeType getType() {
		return type;
	}

	public void setType(SiteNoticeType type) {
		this.type = type;
	}

	public String getOperator() {
		return operator;
	}

	public void setOperator(String operator) {
		this.operator = operator;
	}

	@OneToMany(fetch=FetchType.LAZY, mappedBy="noticeText", cascade={CascadeType.REMOVE})
	public Set<SiteNoticeDomain> getSiteNotices() {
		return siteNotices;
	}

	public void setSiteNotices(Set<SiteNoticeDomain> siteNotices) {
		this.siteNotices = siteNotices;
	}

	public String getOuterUrl() {
		return outerUrl;
	}

	public void setOuterUrl(String outerUrl) {
		this.outerUrl = outerUrl;
	}

	public Boolean getEnabledOuterUrl() {
		return enabledOuterUrl;
	}

	public void setEnabledOuterUrl(Boolean enabledOuterUrl) {
		this.enabledOuterUrl = enabledOuterUrl;
	}
	
}
